package com.yanqu.road.server.cmd.activity.festivalgift;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FestivalGiftProto;
import com.yanqu.road.pb.activity.ShareProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.festivalgift.FestivalGiftModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@CmdApi(reqMsg = FestivalGiftProto.FestivalGiftGetMallListReqMsg.class, respMsg = FestivalGiftProto.FestivalGiftGetMallListRespMsg.class)
@Cmd(code = GameProtocol.S_ACTIVITY_SELF_SELECT_GIFT_GET_MALL_LIST, desc = "获取礼包列表")
public class GetMallListCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FestivalGiftProto.FestivalGiftGetMallListReqMsg req = FestivalGiftProto.FestivalGiftGetMallListReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(FestivalGiftModule.class).getMallList(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            FestivalGiftProto.FestivalGiftGetMallListRespMsg.Builder respMsg = FestivalGiftProto.FestivalGiftGetMallListRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_ACTIVITY_SELF_SELECT_GIFT_GET_MALL_LIST, respMsg);
        }
    }
}
